package com.zx.util;

import java.math.BigDecimal;
import java.util.List;
import java.util.function.Function;

public class NumUtil {

    public static <T> BigDecimal sum(List<T> data, Function<T, BigDecimal> mapper) {
        return data.stream().map(mapper)
                .reduce(BigDecimal::add)
                .orElse(BigDecimal.ZERO);
    }

    public static double format(double d) {
        return Double.parseDouble(String.format("%.2f", d));
    }


}
